/**  
 * All rights Reserved, Designed By <a href="www.itttq.com" target="_blank">www.itttq.com</a>
 * @date:   2017-07-21 11:42:21
 * @Copyright: 2017 <a href="www.itttq.com" target="_blank">www.itttq.com</a> Inc. All rights reserved. 
 */
package com.itttq.gshop.admin.h5.controller.ware;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.itttq.gshop.domain.po.SysSetPo;
import com.itttq.gshop.domain.po.WareInfoPo;
import com.itttq.gshop.domain.to.ResultTo;
import com.itttq.gshop.generic.cmpt.annotation.Auth;
import com.itttq.gshop.generic.connector.ISysSetConnector;
import com.itttq.gshop.generic.connector.IWareInfoConnector;
import com.itttq.gshop.generic.controller.GenericController;
import com.itttq.gshop.generic.util.Constants;
@Auth
@RestController
@RequestMapping("ware")
public class WareInfoController extends GenericController {
	private static final long serialVersionUID = -7435316976064932L;
	@Autowired
	private IWareInfoConnector wareInfoConnector;
	@Autowired
	private ISysSetConnector sysSetConnector;
	/**
	 * 商品列表页面
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("wares.html")
    public ModelAndView getWares(HttpServletRequest request) {
		ModelAndView mv = new ModelAndView("/ware/wares");
		// 获取系统业务设置，主要是积分部分 TODO GXG 考虑一次获取
		SysSetPo set = sysSetConnector.getSysSet(Constants.SCORE_EXCH_RATE);
		mv.addObject(Constants.SCORE_EXCH_RATE, set == null ? 0 : set.getValue());
		set = sysSetConnector.getSysSet(Constants.SCORE_GIVE_RATE);
		mv.addObject(Constants.SCORE_GIVE_RATE, set == null ? 0 : set.getValue());
		set = sysSetConnector.getSysSet(Constants.SCORE_PROMOTE_RATE);
		mv.addObject(Constants.SCORE_PROMOTE_RATE, set == null ? 0 : set.getValue());
        return mv;
    }
	
	/**
	 * 商品列表
	 * 
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("wareContent.html")
    public ModelAndView getWares(WareInfoPo  ware, HttpServletRequest request) {
		ModelAndView mv = new ModelAndView("/ware/wares-content");
		this.getPpt(request, ware);
		mv.addObject("wares", wareInfoConnector.getWares(ware));
        return mv;
    }
	
	/**
	 * 保存商品信息
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("save.html")
	public ResultTo saveUserInfo(WareInfoPo  ware, HttpServletRequest request) {
		ResultTo rt = new ResultTo();
		if(null == ware.getId()) {
			rt.setCode(ResultTo.PARAM_INCORRECT);
			return rt;
		}
		if(wareInfoConnector.saveWareInfo(ware) < 1) {
			rt.setCode(ResultTo.BUSINESS_ERR);
		}
		return rt;
	}
}